package com.ourteam.product.requirement.api;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import com.ourteam.frame.web.AbstractTreeBuilder;
import com.ourteam.frame.web.ITreeNodeBuilder;
import com.ourteam.frame.web.TreeViewNodeBean;

public class ProductFeatureTreeBuilder extends AbstractTreeBuilder {

	private static Map<String, String> nodeActionMap = new HashMap<String, String>();

	static {
		nodeActionMap.put("productFeature", "productFeatureNodeActionGroup");
	}

	private long productDefineId;
	
	private long productVersionId;

	public ProductFeatureTreeBuilder(long productDefineId,long productVersionId) {
		super();
		this.productDefineId = productDefineId;
		this.productVersionId = productVersionId;
	}

	@Override
	protected TreeViewNodeBean configTreeViewNodeProperties(Object obj, TreeViewNodeBean treeViewNodeBean) {

		String actionGroupId = nodeActionMap.get(treeViewNodeBean.getNodeConfigId());

		if (StringUtils.isNotBlank(actionGroupId)) {
			treeViewNodeBean.setActionGroupId(actionGroupId);
		}

		return treeViewNodeBean;
	}

	@Override
	protected String getTreeConfigFile() {
		return "WEB-INF/conf/ui/product/requirement/product_feature_tree.xml";
	}
	
	@Override
	protected void initTreeNodeBuilder(ITreeNodeBuilder treeNodeBuilder) throws Exception {
		if (treeNodeBuilder instanceof ProductFeatureDefineSubNodeBuilder) {
			((ProductFeatureDefineSubNodeBuilder) treeNodeBuilder).setProductDefineId(productDefineId);
			((ProductFeatureDefineSubNodeBuilder) treeNodeBuilder).setProductVersionId(productVersionId);
		}
	}

}
